<extend name="./Application/Admin/View/Layouts/application.html"/>

<block name="content">
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户列表</strong> /
                    <small>User List</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{:U('AuthSet/add_user')}}" class="am-btn am-btn-default"><span
                                    class="am-icon-plus"></span> 新增
                            </a>
                        </div>
                    </div>
                </div>

                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-input-group am-input-group-sm">
                        <input type="text" name="name" class="am-form-field">
                        <span class="am-input-group-btn">
                                <button class="am-btn am-btn-default" type="submit">搜索</button>
                            </span>
                    </div>
                </div>

            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" class="check_all"/>
                                </th>
                                <th>编号</th>
                                <th>用户名</th>
                                <th>所属用户组</th>
                                <th>邮箱</th>
                                <th>创建时间</th>
                                <th>账号状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <volist name="user_manages" id="user_manage">
                                <tr data-id="{{$user_manage.id}}">
                                    <td>
                                        <input type="checkbox" name="ids[]" value=""
                                               class="checked_id"/>
                                    </td>
                                    <td>{{$user_manage.id}}</td>
                                    <td>{{$user_manage.username}}</td>
                                    <td>{{$user_manage.groups|pluck=###, 'title'|implode=', '}}</td>
                                    <td>{{$user_manage.email}}</td>
                                    <td>{{$user_manage.created_at|date='Y-m-d h:i:s',###}}</td>
                                    <td data-status="{{$user_manage.status}}">
                                        <eq name="user_manage.status" value="1">
                                            <a href="javascript:;" class="am-btn am-btn-success am-btn-xs status">已启用</a>
                                            <else/>
                                            <a href="javascript:;" class="am-btn am-btn-danger am-btn-xs status">已禁用</a>
                                        </eq>
                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="{{:U('AuthSet/edit_user',['id'=>$user_manage[id]])}}"
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                        class="am-icon-pencil-square-o"></span> 编辑
                                                </a>

                                                <neq name="user_manage.id" value="1">
                                                    <a href="javascript:void (0);"
                                                       class="delete_user am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                        <span class="am-icon-trash"></span> 删除
                                                    </a>
                                                </neq>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </volist>

                            </tbody>
                        </table>
                    </form>

                    共 {{$user_num}} 条记录
                    <hr/>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

        <!--删除模态框-->
        <div class="am-modal am-modal-confirm" tabindex="-1" id="deleteUser">

            <input type="hidden" id="delete_id">

            <div class="am-modal-dialog">
                <div class="am-modal-hd">Amaze UI</div>
                <div class="am-modal-bd">
                    你，确定要删除这条记录吗？
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                    <span class="am-modal-btn delete_confirm" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>


    </div>
</block>

<block name="js">
    <script>
        $(function () {
            //ajax删除
            $('#doc-modal-list').find('.am-icon-close').add('.delete_user').on('click', function () {
                $('#deleteUser').modal();
                var id = $(this).parents('tr').data('id');
                $('#delete_id').val(id);
            });
            $('.delete_confirm').click(function () {
                var id = $('#delete_id').val();
                var _this = $("tr[data-id='" + id + "']");

                $.post("{{:U('ajax_delete')}}", {id: id}, function (info) {
                    if (info.status == 1) {
                        alert(info.msg);
                        _this.fadeOut(400);
                        $('#deleteUser').modal().hide();
                    } else {
                        alert(info.msg);
                        $('#deleteUser').modal().hide();
                    }
                });
                return false;
            })

            //启用禁用账号
            $('.status').click(function () {
                var id = $(this).parents('tr').data('id');
                var status = $(this).parents('td').attr('data-status');

                $.post("{{:U('change_status')}}",{id:id,status:status},function () {
                    window.location.reload();
                });
                return false;
            })

        })
    </script>
</block>